package initialize

import (
	_ "github.com/mbobakov/grpc-consul-resolver"
	"google.golang.org/grpc"
	"log"
	"order_srv/global"
	"order_srv/goods_proto"
	"order_srv/inventory_proto"
)

func InitSrvConnect() {
	//连接goods微服务
	goodsConn, err := grpc.Dial(
		"consul://127.0.0.1:8500/goods_srv?wait=14s",
		grpc.WithInsecure(),
		grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy": "round_robin"}`),
	)
	if err != nil {
		log.Fatal(err)
	}
	global.GoodsSrvConnect = goods_proto.NewGoodsClient(goodsConn)
	//连接inventory微服务
	inventoryConn, err := grpc.Dial(
		"consul://127.0.0.1:8500/inventory_srv?wait=14s",
		grpc.WithInsecure(),
		grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy": "round_robin"}`),
	)
	if err != nil {
		log.Fatal(err)
	}
	global.InventorySrvConnect = inventory_proto.NewInventoryClient(inventoryConn)
}
